package com.dycong.common.leetcode.yi;

import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yilin
 * Date: 2019-09-10
 * Time: 17:40
 */
public class FindDuplicate {

    public int findDuplicate(int[] nums) {
        Set<Integer> set = new HashSet<>(nums.length);
        for (int item : nums) {
            if (set.contains(item)) {
                return item;
            }
            set.add(item);
        }
        return -1;
    }
}
